package com.example.tonjie.software_park_association;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.Toast;

/**
 * 新消息提醒
 * Created by TonJie on 2017/5/3.
 */

public class New_Message_To_Remind extends Activity {

    private Switch switch_Small_class;//微课堂，新消息提醒
    private Switch department_notice_switch;//部门通知
    private ImageView imageView_return;//返回
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_message_to_remind);
        noti_one();//微课堂通知，switch
        noti_two();//部门通知,switch
        return_s();//返回
    }

    private void return_s() {
        imageView_return= (ImageView) findViewById(R.id.New_Message_To_Remind_return);
        imageView_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(New_Message_To_Remind.this, Setting.class);
                startActivity(intent);
            }
        });
    }

    /**
     * 部门通知,switch
     */
    private void noti_two() {
        department_notice_switch = (Switch) findViewById(R.id.department_notice_switch);
        department_notice_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    noti_two_s();//
                }
            }
        });
    }

    /**
     * 部门通知,switch
     */
    private void noti_two_s() {
        NotificationManager manger= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification=new NotificationCompat.Builder(this)
                .setStyle(new NotificationCompat.BigTextStyle().bigText("请注意，技术部将于第10周接受考核，请认真准备"))
                .setContentText("请注意，技术部将于第10周接受考核，请认真准备")
                .setContentTitle("技术部通知")
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.technical_department)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.technical_department))
                .setDefaults(NotificationCompat.DEFAULT_ALL)
                .setAutoCancel(true)
                .build();
        manger.notify(1,notification);
    }
    /**
     * 微课堂点击事件_2
     */
//    private void notione_s() {
//        Intent intent = new Intent(New_Message_To_Remind.this, Small_class.class);
//        PendingIntent pi = PendingIntent.getActivity(New_Message_To_Remind.this, 0, intent, 0);
//        NotificationManager manger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//        Notification notification = new NotificationCompat.Builder(this)
//                .setContentTitle("本周微课堂通知")
//                .setContentText("本期主题:原型设计工具:Principle，绘图工具,Sketch 老师:袁杰明")
//                .setWhen(System.currentTimeMillis())
//                .setSmallIcon(R.drawable.logo)
//                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo))
//                .setContentIntent(pi)
//                .setDefaults(NotificationCompat.DEFAULT_ALL)
//                .setAutoCancel(true)
//                .build();
//        manger.notify(1, notification);
//    }

    /**
     * 微课堂点击事件_1
     */
    private void noti_one() {
        switch_Small_class = (Switch) findViewById(R.id.switch_Small_class);
        switch_Small_class.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    notione_s();//微课堂通知点击事件实现
                    Toast.makeText(New_Message_To_Remind.this, "Hello", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(New_Message_To_Remind.this, "Hi", Toast.LENGTH_SHORT).show();
                }
            }


        });
    }

    /**
     * 微课堂点击事件_2
     */
    private void notione_s() {
        Intent intent = new Intent(New_Message_To_Remind.this, Small_class.class);
        PendingIntent pi = PendingIntent.getActivity(New_Message_To_Remind.this, 0, intent, 0);
        NotificationManager manger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(this)
                .setContentTitle("本周微课堂通知")
                .setStyle(new NotificationCompat.BigTextStyle().bigText("本期主题:原型设计工具:Principle，绘图工具,Sketch 老师:袁杰明"))
                .setContentText("本期主题:原型设计工具:Principle，绘图工具,Sketch 老师:袁杰明")
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.logo)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo))
                .setContentIntent(pi)
                .setDefaults(NotificationCompat.DEFAULT_ALL)
                .setAutoCancel(true)
                .build();
        manger.notify(1, notification);
    }
}
